from pages.LoginPage import LoginPage
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
from selenium import webdriver

class ChangePwd(LoginPage):
    loc_user = (By.CSS_SELECTOR,'.ant-avatar > i:nth-child(1) > svg:nth-child(1)')
    loc_change = (By.CSS_SELECTOR, 'li.ant-dropdown-menu-item:nth-child(1)')
    loc_oldp = (By.ID, 'old_pwd')
    loc_newp = (By.ID, 'new_pwd')
    loc_notep = (By.ID, 'note_pwd')
    loc_determine = (By.CSS_SELECTOR, 'button.ant-btn:nth-child(1)')


    def __init__(self, browser):
        super().__init__(browser)
        self.login()
        ActionChains(self.driver).move_to_element(self.find_ele(self.loc_user)).perform()
        self.find_ele(self.loc_change).click()

    def change_pwd(self, old, new, note):
        self.find_ele(self.loc_oldp).send_keys(old)
        self.find_ele(self.loc_newp).send_keys(new)
        self.find_ele(self.loc_notep).send_keys(note)
        self.find_ele(self.loc_determine).click()
        sleep(1)
        log_url = self.driver.current_url
        assert log_url == 'http://192.168.1.119/cloud/#/open/login', '修改失败'

if __name__ == '__main__':
    a = ChangePwd(webdriver.Chrome())
    a.change_pwd('12345','z123456','z123456')
